<?php

/**
 * IndexController - Index
 *
 * @author Fernando Dias Oliveira <rodox17@gmail.com>
 * @package intranet
 * @subpackage controller
 */

class RelatorioController extends AppBaseController 
{
	public function init()
	{
		parent::init();		
		
		$this->_helper->layout->disableLayout();
	}
	
	public function savecomentAction()
	{
		$caf04 = new caf04();
		
		if($this->_request->getPost("all"))
		{
			$caf04->saveComentAll($_POST);
		}
		else
		{
			$caf04->saveComent($_POST);
		}
		
		exit;
	}

    public function indexAction() 
    {


    }
    
    public function newAction()
    {
		$caf02 = new caf02();
		
		$this->view->mesas = $caf02->getAll();
    }
    
    public function pedidoAction()
    {
    	$caf02 = new caf02();
   		$caf03 = new caf03();
		
		$arr = $caf03->getArray();
		
		$this->view->arr_menu = $arr;
		
		$this->view->pedido = $this->_request->getPost("cod_mesa");
		$this->view->arr_ped = $caf02->getAllById($this->_request->getPost("cod_mesa"));
    }
    
    public function disactiveAction()
    {
    	$caf02 = new caf02();
    	
    	$caf02->disactivePedido($_POST["cod_pedido"]);
    	
    	exit;
    }
    
    public function listallAction()
    {

    }
    
    public function ajaxlistallAction()
    {
    	$caf04 = new caf04();
    	
    	$this->view->arr_pedido = $caf04->getAll();
    	$this->view->userId     = $this->_request->getPost("user_id"); 	
    	$this->view->gerente    = $this->_request->getPost("gerente"); 	
    }
    
    public function listAction()
    {
    	$caf04 = new caf04();
    	$caf02 = new caf02();
    	
    	$arr = $caf02->getAllById($this->_request->getPost("cod"));
    	$auxArr = array();
    	$total = array();
    	$cod = 0;
    	$prod = "";
    	$pr = 1;
    	$sing = false;
    	$qtdCom = 1;
    	
    	if(!is_array($arr))
    	{
    		$arr = array();
    	}
    	
    	if($menu = $this->_request->getPost("menu"))
    	{
    		$arr_prod = $caf04->getProductsByCodMenu($this->_request->getPost("cod"), $menu);
    	}
    	else
    	{
    		$arr_prod = $caf04->getProductsByCodPedido($_POST["cod"]);
    	}
    	
    	foreach ($arr_prod as $key => $val)
    	{
   			if($prod == $val["caf04_cod_prod"] && $val["caf04_cod_prod"])
    		{
    			if($val["caf04_coment"])
    			{
    				if($coment == $val["caf04_coment"])
    				{
    					$qtdCom++;
    				}
    				else 
    				{
    					$qtd = 1;
    					
    					$qtdCom = 1;
    					
    					$cod++;
    				}
    				
    				if($qtdCom)
    				{
    					$qtd = $qtdCom;
    				}
    				
    				$val["caf04_qtd"] = $qtd;
    			}
    			else
    			{
    				//$sing = true;
    				
					$val["caf04_qtd"] = $pr + 1;
    			}
				
				$auxArr[$cod - $pr] = $val;
    			
				$pr++;
				
    		}
    		else
    		{
    			$qtdCom = 1;
    			
    			$auxArr[$cod] = $val;
    			
    			$pr = 1;
    		}
    		
    		$cod++;
    		
    		$prod = $val["caf04_cod_prod"];
    		$coment = $val["caf04_coment"];
    	}
    	
    	
    	
    	$this->view->arr_pedido = $auxArr;
    	$this->view->res_ped = $arr;
    }
    
    public function ajaxvermesaAction()
    {
    	$caf02 = new caf02();
    	
    	if($caf02->getMesa($this->_request->getPost("mesa")))
    	{
    		echo 1;
    	}
    	
    	exit;
    }
    
    public function saveqtdAction()
    {
    	$caf04 = new caf04();
    	
    	$caf04->saveUn($_POST["cod_menu"], $_POST["cod_item"], $_POST["cod"], $_POST["un"]);
    	
    	exit;
    	
    	//$caf04->
    }
    
    public function deleteqtdAction()
    {
    	$caf04 = new caf04();
    	
    	$caf04->deleteUn($_POST["cod_menu"], $_POST["cod_item"], $_POST["cod"], $_POST["un"]);
    	
    	exit;
    	
    	//$caf04->
    }
    
    public function deleteAction()
    {
    	$caf02 = new caf02();
    	
    	$caf02->delete($this->_request->getPost("cod_pedido"));
    	
    	exit;
    }
    
    public function saveAction()
    {
    	$cab02 = new caf02();
    	
    	echo $cab02->save($_POST);
    	
    	exit;
    }
    
    public function jsonpassAction()
    {
    	$caf01 = new caf01();
    	
    	//print_r($caf01->getUserByPass($_POST["pass"]));
    	$arr = $caf01->getUserByPass($_GET["pass"]);
    	
    	if(is_array($arr))
    	{    	
    		echo json_encode($arr);
    	}
    	else
    	{
    		echo json_encode(array());
    	}
    	
    	exit;
    }
}

?>